﻿namespace iFinance.SqoDAL
{
    using System.Linq;
    using iFinance.Entity;
    using iFinance.IDAL;

    public class UserDAO : IUserDAO
    {
        /// <summary>
        /// 根据用户登录ID判断用户是否 存在
        /// </summary>
        /// <param name="userID">用户登录ID</param>
        /// <returns>是否存在</returns>
        public bool IsUserExist(string userID)
        {
            var users = (from User user in SystemSqoHelper.Instance.DBContext
                         where user.UserID == userID
                         select user).ToList();
            return users == null ? false : users.Count > 0;
        }

        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="user">用户实体</param>
        /// <returns>添加是否成功</returns>
        public bool AddUser(User user)
        {
            return SystemSqoHelper.Instance.Insert(user);
        }

        /// <summary>
        /// 根据用户名获取用户
        /// </summary>
        /// <param name="userID">用户名</param>
        /// <returns>用户信息</returns>
        public User QueryUserByID(string userID)
        {
            var users = (from User user in SystemSqoHelper.Instance.DBContext
                         where user.UserID == userID
                         select user).ToList();
            return users == null || users.Count == 0 ? null : users[0];
        }
    }
}
